*******************************************************************************************************************************************
*------------------------------------------------------------------ STUDY 2 --------------------------------------------------------------*
*---------- Why Are Right-Wing Voters Attracted to Dominant Leaders? Assessing Competing Theories of Psychological Mechanisms ------------*
*******************************************************************************************************************************************

*******************************************************************************************************************************************
*---------------------------------------------- Recodes and generates key variables ------------------------------------------------------*
*******************************************************************************************************************************************


*---------------------------------------------------------- DEPENDENT VARIABLES ----------------------------------------------------------*

*** Creates dependent variable across the five round of choices between non-dominant and dominant face ///
* and based on variable ("dominantrandom") tapping random placement of faces (dominant to the left/right), ///
* and which face represent the party that the respondent voted for in the most recent Danish election

* Round 1
generate DV1 = .
replace DV1 = 1 if q6a_1==1 & dominantrandom1==1
replace DV1 = 1 if q6a_1==1 & dominantrandom1==3
replace DV1 = 1 if q6a_1==2 & dominantrandom1==2
replace DV1 = 1 if q6a_1==2 & dominantrandom1==4

replace DV1 = 0 if q6a_1==1 & dominantrandom1==2
replace DV1 = 0 if q6a_1==1 & dominantrandom1==4
replace DV1 = 0 if q6a_1==2 & dominantrandom1==1
replace DV1 = 0 if q6a_1==2 & dominantrandom1==3

* Round 2
generate DV2 = .
replace DV2 = 1 if q6b_1==1 & dominantrandom2==1
replace DV2 = 1 if q6b_1==1 & dominantrandom2==3
replace DV2 = 1 if q6b_1==2 & dominantrandom2==2
replace DV2 = 1 if q6b_1==2 & dominantrandom2==4

replace DV2 = 0 if q6b_1==1 & dominantrandom2==2
replace DV2 = 0 if q6b_1==1 & dominantrandom2==4
replace DV2 = 0 if q6b_1==2 & dominantrandom2==1
replace DV2 = 0 if q6b_1==2 & dominantrandom2==3

* Round 3
generate DV3 = .
replace DV3 = 1 if q6c_1==1 & dominantrandom3==1
replace DV3 = 1 if q6c_1==1 & dominantrandom3==3
replace DV3 = 1 if q6c_1==2 & dominantrandom3==2
replace DV3 = 1 if q6c_1==2 & dominantrandom3==4

replace DV3 = 0 if q6c_1==1 & dominantrandom3==2
replace DV3 = 0 if q6c_1==1 & dominantrandom3==4
replace DV3 = 0 if q6c_1==2 & dominantrandom3==1
replace DV3 = 0 if q6c_1==2 & dominantrandom3==3

* Round 4
generate DV4 = .
replace DV4 = 1 if q6d_1==1 & dominantrandom4==1
replace DV4 = 1 if q6d_1==1 & dominantrandom4==3
replace DV4 = 1 if q6d_1==2 & dominantrandom4==2
replace DV4 = 1 if q6d_1==2 & dominantrandom4==4

replace DV4 = 0 if q6d_1==1 & dominantrandom4==2
replace DV4 = 0 if q6d_1==1 & dominantrandom4==4
replace DV4 = 0 if q6d_1==2 & dominantrandom4==1
replace DV4 = 0 if q6d_1==2 & dominantrandom4==3

* Round 5
generate DV5 = .
replace DV5 = 1 if q6e_1==1 & dominantrandom5==1
replace DV5 = 1 if q6e_1==1 & dominantrandom5==3
replace DV5 = 1 if q6e_1==2 & dominantrandom5==2
replace DV5 = 1 if q6e_1==2 & dominantrandom5==4

replace DV5 = 0 if q6e_1==1 & dominantrandom5==2
replace DV5 = 0 if q6e_1==1 & dominantrandom5==4
replace DV5 = 0 if q6e_1==2 & dominantrandom5==1
replace DV5 = 0 if q6e_1==2 & dominantrandom5==3


** Creates scale tapping preference for dominant face across the five rounds of choices (only used in correlation table reported in Table S.12.2 in Online Supplementary Material S.12)
egen DV_dominance = rowmean(DV1 DV2 DV3 DV4 DV5)


*-------------------------------------------------------- INDEPENDENT VARIABLES -----------------------------------------------------------------*
*** Party choice
recode q1 (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (8=8) (9=9) (10 11 12=.), generate(party)
label define partyLB 1 "Soc Dem" 2 "Radikale" 3 "Konservative" 4 "SF" 5 "Liberal Alliance" 6 "Kristendemokraterne" 7 "Dansk Folkeparti" 8 "Venstre" 9 "Enhedslisten"
label values party partyLB


* Creates dummy variable for whether subject voted for a party from the leftwing ("0" or rightwing ("1") party block
recode q1 (1 2 4 9 = 0) (3 5 6 7 8 = 1) (10 11 12=.), generate(rightwing)
label define rightwingLB 0 "leftwing" 1 "rightwing"
label values rightwing rightwingLB


*** Politcal ideology measured as subjects' left-right self-placement on 0-1 scale reflecting most leftwing/liberal ("0") and rightwing/conservative ("1") position, respectively.
generate LR_Ideology = (q2-1)/10
summ LR_Ideology


*** Social Dominance Orientation
alpha q3_1 q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8
recode q3_3 q3_4 q3_7 q3_8 (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)
corr q3_1 q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8
* recodes to 0-1 scale with "0" and "1" indicating min. and max. values, respectively
generate SDO = ((q3_1+q3_2+q3_3+q3_4+q3_5+q3_6+q3_7+q3_8)-8)/48
summ SDO


*** Rightwing Authoritarianism
alpha q4_1 q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8
recode q4_2 q4_6 q4_7 q4_8 (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)
corr q4_1 q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8
* recodes to 0-1 scale with "0" and "1" indicating min. and max. values, respectively
generate RWA = ((q4_1+q4_2+q4_3+q4_4+q4_5+q4_6+q4_7+q4_8)-8)/48


*--------------------------------------------------------- INDEPENDENT VARIABLES BASED ON THE PARTIES ASSIGNED TO CANDIDATE FACES -------------------------------------------------*
*** Creates independent variable tapping whether the dominant ("1") or the non-dominant ("0") candidate face represents the party that the respondent voted for in the most recent Danish election
** Creates one variable per round:
* Round 1
generate domi_matched1 =. 
replace domi_matched1 = 1 if dominantrandom1==1
replace domi_matched1 = 1 if dominantrandom1==4
replace domi_matched1 = 0 if dominantrandom1==2
replace domi_matched1 = 0 if dominantrandom1==3

* Round 2
generate domi_matched2 =. 
replace domi_matched2 = 1 if dominantrandom2==1
replace domi_matched2 = 1 if dominantrandom2==4
replace domi_matched2 = 0 if dominantrandom2==2
replace domi_matched2 = 0 if dominantrandom2==3

* Round 3
generate domi_matched3 =. 
replace domi_matched3 = 1 if dominantrandom3==1
replace domi_matched3 = 1 if dominantrandom3==4
replace domi_matched3 = 0 if dominantrandom3==2
replace domi_matched3 = 0 if dominantrandom3==3

* Round 4
generate domi_matched4 =. 
replace domi_matched4 = 1 if dominantrandom4==1
replace domi_matched4 = 1 if dominantrandom4==4
replace domi_matched4 = 0 if dominantrandom4==2
replace domi_matched4 = 0 if dominantrandom4==3

* Round 5
generate domi_matched5 =. 
replace domi_matched5 = 1 if dominantrandom5==1
replace domi_matched5 = 1 if dominantrandom5==4
replace domi_matched5 = 0 if dominantrandom5==2
replace domi_matched5 = 0 if dominantrandom5==3


*** Creates a variable measuring if respondents choose the candidate face that represents the party they voted for in the most recent Danish election
* (only used in the "preliminary analyses" section under Study 2) 

** Creates one variable per round:
* Round 1
generate party_match1=.
replace party_match1 = 1 if q6a_1==1 & dominantrandom1==1
replace party_match1 = 1 if q6a_1==1 & dominantrandom1==2
replace party_match1 = 1 if q6a_1==2 & dominantrandom1==3
replace party_match1 = 1 if q6a_1==2 & dominantrandom1==4

replace party_match1 = 0 if q6a_1==2 & dominantrandom1==1
replace party_match1 = 0 if q6a_1==2 & dominantrandom1==2
replace party_match1 = 0 if q6a_1==1 & dominantrandom1==3
replace party_match1 = 0 if q6a_1==1 & dominantrandom1==4

* Round 2
generate party_match2=.
replace party_match2 = 1 if q6b_1==1 & dominantrandom2==1
replace party_match2 = 1 if q6b_1==1 & dominantrandom2==2
replace party_match2 = 1 if q6b_1==2 & dominantrandom2==3
replace party_match2 = 1 if q6b_1==2 & dominantrandom2==4

replace party_match2 = 0 if q6b_1==2 & dominantrandom2==1
replace party_match2 = 0 if q6b_1==2 & dominantrandom2==2
replace party_match2 = 0 if q6b_1==1 & dominantrandom2==3
replace party_match2 = 0 if q6b_1==1 & dominantrandom2==4

* Round 3
generate party_match3=.
replace party_match3 = 1 if q6c_1==1 & dominantrandom3==1
replace party_match3 = 1 if q6c_1==1 & dominantrandom3==2
replace party_match3 = 1 if q6c_1==2 & dominantrandom3==3
replace party_match3 = 1 if q6c_1==2 & dominantrandom3==4

replace party_match3 = 0 if q6c_1==2 & dominantrandom3==1
replace party_match3 = 0 if q6c_1==2 & dominantrandom3==2
replace party_match3 = 0 if q6c_1==1 & dominantrandom3==3
replace party_match3 = 0 if q6c_1==1 & dominantrandom3==4

* Round 4
generate party_match4=.
replace party_match4 = 1 if q6d_1==1 & dominantrandom4==1
replace party_match4 = 1 if q6d_1==1 & dominantrandom4==2
replace party_match4 = 1 if q6d_1==2 & dominantrandom4==3
replace party_match4 = 1 if q6d_1==2 & dominantrandom4==4

replace party_match4 = 0 if q6d_1==2 & dominantrandom4==1
replace party_match4 = 0 if q6d_1==2 & dominantrandom4==2
replace party_match4 = 0 if q6d_1==1 & dominantrandom4==3
replace party_match4 = 0 if q6d_1==1 & dominantrandom4==4

* Round 5
generate party_match5=.
replace party_match5 = 1 if q6e_1==1 & dominantrandom5==1
replace party_match5 = 1 if q6e_1==1 & dominantrandom5==2
replace party_match5 = 1 if q6e_1==2 & dominantrandom5==3
replace party_match5 = 1 if q6e_1==2 & dominantrandom5==4

replace party_match5 = 0 if q6e_1==2 & dominantrandom5==1
replace party_match5 = 0 if q6e_1==2 & dominantrandom5==2
replace party_match5 = 0 if q6e_1==1 & dominantrandom5==3
replace party_match5 = 0 if q6e_1==1 & dominantrandom5==4


*** Creates a variable measuring if the party of the "out-party" face (the party that is different from what the respondent voted for in the most recent Danish election),
* belongs to the same party block or the other party block as the party, the respondent voted for

** Creates variable tapping if the "out-party" face represents the leftwing ("0") or the rightwing ("1") party block (varies across rounds)
recode parti1 (1 2 4 9 10 = 0) (3 5 6 7 8 =1), generate(OutpartyCand_rightwing1)
recode parti2 (1 2 4 9 10 = 0) (3 5 6 7 8 =1), generate(OutpartyCand_rightwing2)
recode parti3 (1 2 4 9 10 = 0) (3 5 6 7 8 =1), generate(OutpartyCand_rightwing3)
recode parti4 (1 2 4 9 10 = 0) (3 5 6 7 8 =1), generate(OutpartyCand_rightwing4)
recode parti5 (1 2 4 9 10 = 0) (3 5 6 7 8 =1), generate(OutpartyCand_rightwing5)

** Creates variable tapping if the "in-party" face (the party that the respondent voted for in the most recent Danish election)
* represents the leftwing ("0") or the rightwing ("1") party block (constant across rounds)
recode parti_hist (1 2 4 9 10 = 0) (3 5 6 7 8 =1), generate(InpartyCand_rightwing)

** Creates variable measuring if "out-party" and "in-party" candidate faces belong to the same party block ("1") or to different party blocks ("0") - one variable per round
* Round 1
generate Cand2_blockmatch1=.
replace Cand2_blockmatch1 = 0 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing1 == 1
replace Cand2_blockmatch1 = 0 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing1 == 0
replace Cand2_blockmatch1 = 1 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing1 == 1
replace Cand2_blockmatch1 = 1 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing1 == 0

* Round 2
generate Cand2_blockmatch2=.
replace Cand2_blockmatch2 = 0 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing2 == 1
replace Cand2_blockmatch2 = 0 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing2 == 0
replace Cand2_blockmatch2 = 1 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing2 == 1
replace Cand2_blockmatch2 = 1 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing2 == 0

* Round 3
generate Cand2_blockmatch3=.
replace Cand2_blockmatch3 = 0 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing3 == 1
replace Cand2_blockmatch3 = 0 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing3 == 0
replace Cand2_blockmatch3 = 1 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing3 == 1
replace Cand2_blockmatch3 = 1 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing3 == 0

* Round 4
generate Cand2_blockmatch4=.
replace Cand2_blockmatch4 = 0 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing4 == 1
replace Cand2_blockmatch4 = 0 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing4 == 0
replace Cand2_blockmatch4 = 1 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing4 == 1
replace Cand2_blockmatch4 = 1 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing4 == 0

* Round 5
generate Cand2_blockmatch5=.
replace Cand2_blockmatch5 = 0 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing5 == 1
replace Cand2_blockmatch5 = 0 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing5 == 0
replace Cand2_blockmatch5 = 1 if InpartyCand_rightwing == 1 & OutpartyCand_rightwing5 == 1
replace Cand2_blockmatch5 = 1 if InpartyCand_rightwing == 0 & OutpartyCand_rightwing5 == 0


*** Creates a variable that measures perceived ideological distance between the respondent and the "out-party" candidate face
* (calculated as the difference between respondent's self-reported ideology and average ideological placement of a given "out-party" in the 2015 Danish Election Study)
* One variable per round

* Round 1
generate perceived_ideo_dist1 = .
replace perceived_ideo_dist1 = LR_Ideology - 0.4286035 if parti1 == 1
replace perceived_ideo_dist1 = LR_Ideology - 0.4728894 if parti1 == 2
replace perceived_ideo_dist1 = LR_Ideology - 0.7095632 if parti1 == 3
replace perceived_ideo_dist1 = LR_Ideology - 0.2893004 if parti1 == 4
replace perceived_ideo_dist1 = LR_Ideology - 0.7398325 if parti1 == 5
replace perceived_ideo_dist1 = LR_Ideology - 0.7050488 if parti1 == 7
replace perceived_ideo_dist1 = LR_Ideology - 0.6842785 if parti1 == 8
replace perceived_ideo_dist1 = LR_Ideology - 0.1736659 if parti1 == 9
replace perceived_ideo_dist1 = LR_Ideology - 0.3004838 if parti1 == 10

* Round 2
generate perceived_ideo_dist2 = .
replace perceived_ideo_dist2 = LR_Ideology - 0.4286035 if parti2 == 1
replace perceived_ideo_dist2 = LR_Ideology - 0.4728894 if parti2 == 2
replace perceived_ideo_dist2 = LR_Ideology - 0.7095632 if parti2 == 3
replace perceived_ideo_dist2 = LR_Ideology - 0.2893004 if parti2 == 4
replace perceived_ideo_dist2 = LR_Ideology - 0.7398325 if parti2 == 5
replace perceived_ideo_dist2 = LR_Ideology - 0.7050488 if parti2 == 7
replace perceived_ideo_dist2 = LR_Ideology - 0.6842785 if parti2 == 8
replace perceived_ideo_dist2 = LR_Ideology - 0.1736659 if parti2 == 9
replace perceived_ideo_dist2 = LR_Ideology - 0.3004838 if parti2 == 10

* Round 3
generate perceived_ideo_dist3 = .
replace perceived_ideo_dist3 = LR_Ideology - 0.4286035 if parti3 == 1
replace perceived_ideo_dist3 = LR_Ideology - 0.4728894 if parti3 == 2
replace perceived_ideo_dist3 = LR_Ideology - 0.7095632 if parti3 == 3
replace perceived_ideo_dist3 = LR_Ideology - 0.2893004 if parti3 == 4
replace perceived_ideo_dist3 = LR_Ideology - 0.7398325 if parti3 == 5
replace perceived_ideo_dist3 = LR_Ideology - 0.7050488 if parti3 == 7
replace perceived_ideo_dist3 = LR_Ideology - 0.6842785 if parti3 == 8
replace perceived_ideo_dist3 = LR_Ideology - 0.1736659 if parti3 == 9
replace perceived_ideo_dist3 = LR_Ideology - 0.3004838 if parti3 == 10

* Round 4
generate perceived_ideo_dist4 = .
replace perceived_ideo_dist4 = LR_Ideology - 0.4286035 if parti4 == 1
replace perceived_ideo_dist4 = LR_Ideology - 0.4728894 if parti4 == 2
replace perceived_ideo_dist4 = LR_Ideology - 0.7095632 if parti4 == 3
replace perceived_ideo_dist4 = LR_Ideology - 0.2893004 if parti4 == 4
replace perceived_ideo_dist4 = LR_Ideology - 0.7398325 if parti4 == 5
replace perceived_ideo_dist4 = LR_Ideology - 0.7050488 if parti4 == 7
replace perceived_ideo_dist4 = LR_Ideology - 0.6842785 if parti4 == 8
replace perceived_ideo_dist4 = LR_Ideology - 0.1736659 if parti4 == 9
replace perceived_ideo_dist4 = LR_Ideology - 0.3004838 if parti4 == 10

* Round 5
generate perceived_ideo_dist5 = .
replace perceived_ideo_dist5 = LR_Ideology - 0.4286035 if parti5 == 1
replace perceived_ideo_dist5 = LR_Ideology - 0.4728894 if parti5 == 2
replace perceived_ideo_dist5 = LR_Ideology - 0.7095632 if parti5 == 3
replace perceived_ideo_dist5 = LR_Ideology - 0.2893004 if parti5 == 4
replace perceived_ideo_dist5 = LR_Ideology - 0.7398325 if parti5 == 5
replace perceived_ideo_dist5 = LR_Ideology - 0.7050488 if parti5 == 7
replace perceived_ideo_dist5 = LR_Ideology - 0.6842785 if parti5 == 8
replace perceived_ideo_dist5 = LR_Ideology - 0.1736659 if parti5 == 9
replace perceived_ideo_dist5 = LR_Ideology - 0.3004838 if parti5 == 10


** Creates variable for absolute perceived ideological proximity of "out-party" candidate face
* (calculated as the absolute value for perceived ideological distance between respondent and out-party candidate)
generate proximity1 = abs(perceived_ideo_dist1)
generate proximity2 = abs(perceived_ideo_dist2)
generate proximity3 = abs(perceived_ideo_dist3)
generate proximity4 = abs(perceived_ideo_dist4)
generate proximity5 = abs(perceived_ideo_dist5)


*------------------------------------------------------ DEMOGRAPHICS AND BACKGROUND VARIABLES -------------------------------------------------------*
*** Gender
recode gender (1=0) (2=1)
label define genderLB 0 "female" 1 "male"
label values gender genderLB 

*** Age 
summ age

*** Education
tab education
recode education (1=1) (4=2) (2 3 = 3) (5=4) (6=5) (7=6) (8=7), generate(education1)
generate educ = (education1-1)/6

*** Regional belonging
generate Region = region-1
label define RegionLB 0 "Hovedstaden" 1 "Sjælland" 2 "Syddanmark" 3 "Midtjylland" 4 "Nordjylland"
label values Region RegionLB 
* Creates dummy variables for the five regional categories
tab region, generate(reg_)


*-------------------------------------------------------------- DEMOGRAPHICS AND BACKGROUND VARIABLES -------------------------------------------------------------*
*------------------------------------------------- reported in OnlineSupplementary Materials S.12, Table S.12.1 ---------------------------------------------------*

*** Gender
tab gender

*** Age
summ age

*** Education
tab education

*** Regional belonging
tab Region

*** Ideological self-placement
summ LR_Ideology

*** Social Dominance Orientation
summ SDO

*** Party preference
tab party

*** Rightwing Authoritarianiam
summ RWA



***********************************************************************************************************************************************************
************************ Correlation matrix for Online Supplementary Materials PART 1 (Online Supplementary Materials S.1 *********************************
***********************************************************************************************************************************************************

** Means and standard deviations for all variables except assigned condition of political agreement and the interaction between assigned political agreement and ideology
summ DV_dominance LR_Ideology SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5

** Correlations between all variables except assigned condition of political agreement and the interaction between assigned political agreement and ideology
corr DV_dominance LR_Ideology SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5


***********************************************************************************************************************************************************
************************************************* Reshapes dataset to long format *************************************************************************
reshape long DV domi_matched party_match Cand2_blockmatch proximity, i(RecordNo) j(round)
***********************************************************************************************************************************************************
***********************************************************************************************************************************************************

** Creates interaction between "out-party" candidate's party block (same or different from respondent's) and ideology
generate LR_Ideology_Cand2_blockmatch  = LR_Ideology * Cand2_blockmatch

** Creates interaction between proximity of out-party candidate and ideology
generate LR_Ideology_proximity = LR_Ideology * proximity


** Means and standard deviations for variables varying within respondents as a consequence of the assigned experimental condition for out-party candidate's party.
* Variabels are: 1) shared part with dominant or non-dominant candidate face, 2) variable measuring shared/different party block for out-party candidate compared to respondent, ///
* 3) Interaction between out-party candidate's party block (same/different from respondent's) 4) ideological proximity of out-party candidate, 5) interaction between ideological proximity of out-party candiadte and ideology
summ domi_matched Cand2_blockmatch LR_Ideology_Cand2_blockmatch proximity LR_Ideology_proximity

** Correlations for variables varying within respondents depending on the assigned condition of partisanship for the out-party candidate

* 1) Does respondent share party with the dominant (coded "1") or the non-dominant (coded "0") candidate face
foreach var in DV LR_Ideology SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5 {
corr `var' domi_matched
}
 
 
* 2) Does out-party candidate represent party from same or different block compared to respondents' party
foreach var in DV LR_Ideology domi_matched SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5 {
corr `var' Cand2_blockmatch
}


* 3) Interaction between variable for out-party candidate's party (same or different block compared to respondent) and ideology
foreach var in DV LR_Ideology domi_matched Cand2_blockmatch SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5 {
corr `var' LR_Ideology_Cand2_blockmatch
}


* 4) Perceived ideological proximity of out-party candidate's party
foreach var in DV LR_Ideology domi_matched Cand2_blockmatch LR_Ideology_Cand2_blockmatch SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5 {
corr `var' proximity
}


* 5) Interaction between proximity of out-party candidate and ideology
foreach var in DV LR_Ideology domi_matched Cand2_blockmatch LR_Ideology_Cand2_blockmatch proximity SDO RWA educ age gender reg_1 reg_2 reg_3 reg_4 reg_5 {
corr `var' LR_Ideology_proximity
}


************************************************************************************************************************************************************
******************************************************** MAIN ANALYSES *************************************************************************************
************************************************************************************************************************************************************

****************************************************** Preliminary analyses ***************************************************************
* How have faces been pitted against each other across rounds?
tab dominante1 ikkedominante1 if round == 1
tab dominante2 ikkedominante2 if round == 2
tab dominante3 ikkedominante3 if round == 3
tab dominante4 ikkedominante4 if round == 4
tab dominante5 ikkedominante5 if round == 5

* Tests if subjects hold an average preference for dominant over non-dominant candidate faces. --> No difference from 0.5
prtest DV==0.5 if party!=.

* Do aggregate preferences for dominant over non-dominant candidate face differ across the five rounds? --> No!
logit DV i.round if party!=., cluster(RecordNo)
margins, at(round=(1 2 3 4 5))
testparm i.round


*** Proportion choosing own party candidate
prtest party_match == 0.5 if party!=.


*********************************************************************************************************************************************************
**************************************** Main effects of ideology on preference for dominant candidate face *********************************************
*********************************************************************************************************************************************************

**** Do conservatives compared to liberals hold stronger preferences for dominant looking candidates when having received information about candidates’' partisanships?
** Without including shared party with one of the candidates (variable "domi_matched") as a predictor variable (Table 2: Model 1)
logit DV c.LR_Ideology i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV c.LR_Ideology i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

** Also including candidate party as a predictor variable (Table 2: Model 2)
logit DV i.domi_matched c.LR_Ideology i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.LR_Ideology i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)


*** Creates Figure 4
logit DV i.domi_matched c.LR_Ideology i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
margins, dydx(LR_Ideology) at(domi_matched=(0 1))
marginsplot, recastci(rcap) ciopts(lpattern(dash)) recast(scatter) yline(0) xlabel(0 "Party shared Non-Dominant" 1 "Party shared Dominant") ///
xtitle(Shared partisanship) ytitle("Marginal Effect of Ideology" "on Preference for Dominant Leader Face") title("") scheme(s2mono)


**** Does ideology predict preferences for dominant looking candidates when respondents face a choice between an in-party candidate and an ideological proximate alternative?
** Does ideology predict preferences for dominant face, when the out-party candidate represents a party from same party block  
* as the respondent's party - i.e. an ideologically proximate party? (Table 2: Model 3)
logit DV i.domi_matched c.LR_Ideology##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.LR_Ideology##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)
* Same analysis but changing the reference category for the variable "Cand2_blockmatch" such that the coefficient for Ideology captures ///
* the relationship between ideology and pref. for dominant when the "out-party" candidate is from the same block as the "in-party" candidate (and, thus, the respondent)
logit DV i.domi_matched c.LR_Ideology##ib(1).Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.LR_Ideology##ib(1).Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)


** Does ideology interact with ideological proximity of the out-party candidate?
* That is, does ideology positively predict preferences for dominant candiadte faces ONLY when the out-party candidate 
* is represents a party ideologically proximate to the respondent's party? (Table 2: Model 4)
logit DV i.domi_matched c.LR_Ideology##c.proximity i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.LR_Ideology##c.proximity i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)


*************************************************************************************************************************************************************
************************************************** Online Supplementary Analyses ****************************************************************************
*************************************************************************************************************************************************************

** S.13: Replicates results in Table 2 from Linear Probability Model
* Table S.13: Model 1
reg DV c.LR_Ideology i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
* Table S.13: Model 2
reg DV i.domi_matched c.LR_Ideology i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
* Table S.13: Model 3
reg DV i.domi_matched c.LR_Ideology##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
* Table S.13: Model 4
reg DV i.domi_matched c.LR_Ideology##c.proximity i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)



* Replicates results using dichotomous ideology variable as predictor variable of pref. for dominant candidate faces (Online Supplementary Materials S.14)
* Table S.14: Model 1
logit DV i.rightwing i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.rightwing i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

* Table S.14: Model 2 (controlling for candidate party as a predictor variable)
logit DV i.domi_matched i.rightwing i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched i.rightwing i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

* Table S.14: Model 3 (interaction between ideology and Candidates' party block)
logit DV i.domi_matched i.rightwing##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched i.rightwing##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

* Table S.14: Model 4 (interaction between ideology and proximity of out-party candidate)
logit DV i.domi_matched i.rightwing##c.proximity i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched i.rightwing##c.proximity i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)


* Replicates results using Social Dominance Orientation rather than ideology as predictor variable of pref. for dominant candidate faces (Online Supplementary Materials S.15)
* Table S.15: Model 1
logit DV c.SDO i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV c.SDO i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

* Table S.15: Model 2 (controlling for candidate party as a predictor variable)
logit DV i.domi_matched c.SDO i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.SDO i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

* Table S.15: Model 3 (interaction between ideology and Candidates' party block)
logit DV i.domi_matched c.SDO##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.SDO##i.Cand2_blockmatch i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)

* Table S.15: Model 4 (interaction between ideology and proximity of out-party candidate)
logit DV i.domi_matched c.SDO##c.proximity i.gender c.age c.educ i.Region if party!=., cluster(RecordNo)
logit DV i.domi_matched c.SDO##c.proximity i.gender c.age c.educ i.Region if party!=., or cluster(RecordNo)
